from app.services.reques_http import RequestHandler
from flask import Blueprint
from app import app

import json
from common import CentralPeoplesGovernmentCommon
from flask.json import jsonify
from app.services.JSONResponse import JSONResponse
from flask import request

home_page_bp = Blueprint(
    'home_page', __name__, url_prefix='/' + CentralPeoplesGovernmentCommon().home_page)

# 首页


@home_page_bp.route('/', methods=['POST'])
def index():
    print("jin ru")
    _from = request.args.get("from")
    _size = request.args.get("size")
    print(_from)
    # return "get math"
    # get请求接口
    url = CentralPeoplesGovernmentCommon().Url + "/_search"
    # body请求的body
    payload = {
        "from": _from,
        "size": _size,

    }
    res = RequestHandler().get(url=url, params=payload)
    print(res)
    newRes = res.json()['hits']['hits']
    list = []
    for item in newRes:
        list.append(item['_source'])
    return JSONResponse(list)
